package com.bms.common;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

import com.bms.utils.DateUtil;

/**
 * 将前台传递过来的属性数据进行处理
 * @author Lan
 */
@Component
public class CustomBindingInitializer implements WebBindingInitializer {

	public void initBinder(WebDataBinder binder, WebRequest request) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.LONG_DATE);
		dateFormat.setLenient(false);
		//Bean中Date类型属性的处理:将前台传递过来的日期格式的字符串，自动转化为Date类型
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
		//Bean中String类型属性的处理
		binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	}

}
